package edu.ubbcs.rs.backend.service.basic;

import edu.ubbcs.rs.backend.model.Reservation;
import edu.ubbcs.rs.backend.model.ReservationEvent;
import edu.ubbcs.rs.backend.model.room.Room;
import edu.ubbcs.rs.backend.model.room.WeddingRoomDecorator;
import edu.ubbcs.rs.backend.model.room.WeekdayRoom;
import edu.ubbcs.rs.backend.model.table.Table;
import edu.ubbcs.rs.backend.service.ReservationService;
import edu.ubbcs.rs.backend.service.RoomService;
import edu.ubbcs.rs.backend.service.TableService;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;

/**
 * @author Merli Andras-Bertalan
 * @version 1.0
 * @created 09-jan.-2015 15:37:43
 */
@Stateless(name = "RoomService")
public class BasicRoomService implements RoomService {

    @Inject
    private ReservationService reservationService;
    @Inject
    private TableService tableService;

    @Override
    public List<Room> getRoomsByDate(Date date) {
        List<Reservation> reservations = reservationService.getReservationsByDate(date);
        List<Table> tables = tableService.getAll();
        List<Room> rooms = new LinkedList<>();
        for (int i = 10; i < 20; i++) {
            Room room = new WeekdayRoom(date, i);
            room.setTables(tables);
            List<Reservation> reservationsForHour = new LinkedList<>();
            boolean wedding = false;
            for (Reservation reservation : reservations) {
                if (reservation.getHour() == i) {
                    if (ReservationEvent.WEDDING.equals(reservation.getReservationEvent())) {
                        wedding = true;
                    }
                    reservationsForHour.add(reservation);
                }
            }
            room.setReservations(reservationsForHour);
            if (wedding) {
                room = new WeddingRoomDecorator(room);
            }
            rooms.add(room);
        }
        return rooms;
    }

    @Override
    public List<Room> getAll() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Room getById(Long id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void insert(Room item) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void update(Room item) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void delete(Room item) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void deleteAll() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Long getCount() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
